<template>
	<view>
		<l-function-list :functionData="functionData" @setWifiPlay="setWifiPlay" @setWifiDownload="setWifiDownload"
			@setAutoPlay="setAutoPlay" @clearStorage="clearStorage"></l-function-list>
	</view>
</template>

<script>
	// 组件
	import lFunctionList from "../../components/l-function-list.vue"
	// 数据	
	import settingData from "../../common/mock/setting-list.js"

	export default {
		components: {
			lFunctionList
		},
		data() {
			return {
				functionData: settingData(),
			};
		},
		methods: {
			// 允许非WIFI网络播放
			setWifiPlay(item) {
				this.saveStorage(item, 'wifi-play')
			},
			// 允许非WIFI网络缓存
			setWifiDownload(item) {
				this.saveStorage(item, 'wifi-download')
			},

			// 视频自动连续播放
			setAutoPlay(item) {
				this.saveStorage(item, 'auto-play')
			},

			// 清除应用缓存
			clearStorage(item) {
				uni.showModal({
					title: '您确定清除应用缓存吗?',
					content: '(该操作不会删除缓存课程)',
					success: (res) => {
						if (res.confirm) {
							// uni.clearStorageSync()
							uni.clearStorage()
							this.$set(item, 'text', '0KB')
							// this.$util.msg('清除成功')
							// 解决清空缓存后按钮不更新的情况
							this.functionData = settingData()
							console.log(this.functionData)
							this.$util.msg('清除成功')
						}
					}
				})
			},

			// 本地存储
			saveStorage(item, key) {
				const checked = !item.checked
				this.$set(item, item.checked, checked)
				uni.setStorageSync(key, checked)
				// uni.setStorage({ key, data: checked })
			}
		}
	}
</script>

<style lang="scss">

</style>
